<?php
include_once 'app/until/GFW_database.php';

class Db_modul extends Model_Db_Core {

	protected  $con = null;
	protected  $modul = null;

	function __construct(){
		//
	}
	public function GetModulWidget($id){
	    $filter  = array('modul_id'=> $id);
	    $select  = array();
	    
	    parent::getSQLResult("Db_modul_widget",$filter,$select);
	    $this->modul = parent::result(1);

	    return $this->modul;
	}
    public function getModul($user_id,$url){
		$sql = 'Select upe.id as ExpId, upe.*, usp.* from user_page_explorer upe, modul usp where upe.url="'.$url.'" and upe.user_id = '.$user_id.' and upe.modul_nr = usp.id';

		parent::setSqlManuel($sql);
	    $this->modul = parent::result(1);
	    		
		return $this->modul;
	}
    public function getModulList(){
        $filter  = array();
	    $select  = array("id","name","price");
	    
	    parent::getSQLResult(__CLASS__,$filter,$select,0,99);
	    $this->modul = parent::result();

	    return $this->modul;
	}
    public function getModulSetting($id){
        $filter  = array('id' => $id);
	    $select  = array();
	    
	    parent::getSQLResult(__CLASS__,$filter,$select);
	    $this->modul = parent::result(1);
	    
	    return $this->modul;
	}
    public function checkIfUserHaveAktiv($userID,$modulID){
        $filter  = array("UserID" => $userID, "ModulID" => $modulID);
	    $select  = array("ID","Date");
	    
	    parent::getSQLResult("Db_user_page_modul",$filter,$select);
	    $this->modul = parent::result(1);

	    return $this->modul;
	}  
	public function aktivModul($userID,$modulID){
	    parent::setInsert("Db_user_page_modul");
		 	 	
		$this->value['UserID'] = $userID;
		$this->value['ModulID'] = $modulID;
		$this->value['Date'] = "CURRENT_TIMESTAMP";
				
	    $status = $this->writeToDb();
	   
	    return $status;	   
	}
	public function delModul($userID,$modulID){
	   	$sql = "DELETE FROM `user_page_modul` WHERE `UserID` = $userID and ModulID = $modulID ";

		parent::setSqlManuel($sql);   		
		return true;
	}
}

?>